package com.yuanqi.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yuanqi.pojo.SalesOrderAttachment;
import com.yuanqi.dto.SalesOrderAttachmentDTO;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 销售订单附件服务接口
 */
public interface SalesOrderAttachmentService extends IService<SalesOrderAttachment> {
    
    /**
     * 上传附件
     */
    SalesOrderAttachmentDTO uploadAttachment(Long soId, MultipartFile file, String description, String uploader) throws IOException;
    
    /**
     * 批量上传附件
     */
    List<SalesOrderAttachmentDTO> uploadAttachments(Long soId, MultipartFile[] files, String description, String uploader) throws IOException;
    
    /**
     * 下载附件
     */
    void downloadAttachment(Long attachmentId, HttpServletResponse response) throws IOException;
    
    /**
     * 批量下载附件（打包成ZIP）
     */
    void downloadAttachmentsAsZip(List<Long> attachmentIds, HttpServletResponse response) throws IOException;
    
    /**
     * 删除附件
     */
    boolean deleteAttachment(Long attachmentId);
    
    /**
     * 批量删除附件
     */
    boolean deleteAttachments(List<Long> attachmentIds);
    
    /**
     * 根据订单ID查询附件列表
     */
    List<SalesOrderAttachmentDTO> getAttachmentsBySoId(Long soId);
    
    /**
     * 根据订单ID查询有效附件列表
     */
    List<SalesOrderAttachmentDTO> getValidAttachmentsBySoId(Long soId);
    
    /**
     * 分页查询附件
     */
    IPage<SalesOrderAttachmentDTO> pageAttachments(Page<SalesOrderAttachment> page, Long soId, String attachmentType, String uploader);
    
    /**
     * 根据附件类型查询附件列表
     */
    List<SalesOrderAttachmentDTO> getAttachmentsByType(String attachmentType);
    
    /**
     * 根据上传人查询附件列表
     */
    List<SalesOrderAttachmentDTO> getAttachmentsByUploader(String uploader);
    
    /**
     * 统计订单附件数量
     */
    Long countAttachmentsBySoId(Long soId);
    
    /**
     * 统计订单有效附件数量
     */
    Long countValidAttachmentsBySoId(Long soId);
    
    /**
     * 预览附件（图片类型）
     */
    byte[] previewAttachment(Long attachmentId) throws IOException;
    
    /**
     * 获取附件信息（不包含文件内容）
     */
    SalesOrderAttachmentDTO getAttachmentInfo(Long attachmentId);
    
    /**
     * 更新附件描述
     */
    boolean updateAttachmentDescription(Long attachmentId, String description);
    
    /**
     * 检查附件是否存在
     */
    boolean checkAttachmentExists(Long attachmentId);
    
    /**
     * 验证文件类型是否允许
     */
    boolean isAllowedFileType(String fileName);
    
    /**
     * 获取允许的文件类型列表
     */
    List<String> getAllowedFileTypes();
    
    /**
     * 获取最大文件大小（字节）
     */
    long getMaxFileSize();
}
